<template>
  <div class="content">
    <div class="title">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/' }"><b>逾期清单</b></el-breadcrumb-item>
      </el-breadcrumb>
    </div>

    <div class="main-content">
      <!--工具条-->
      <el-form :inline="true" :model="filters">

        <el-col :span="24" class="toolbar" style="margin-bottom: 20px">
          <el-upload
            class="upload-demo"
            action="http://localhost:8080/overdue/list/upload"
            :multiple="true"
            :on-preview="handlePreview"
            :on-remove="handleRemove"
            :file-list="fileList"
            :on-success="uploadSuccess">
            <el-button size="small" type="primary">点击上传</el-button>
            <div slot="tip" class="el-upload__tip">支持扩展名：.xlx.xlxs</div>
          </el-upload><hr/>
          <el-form-item>
            <el-input size="35px" v-model="filters.name" placeholder="请输入姓名/身份证号/贷款银行" style="min-width: 240px;" icon="search"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="searchCustomer">搜索</el-button>
          </el-form-item>
        </el-col>
      </el-form>

      <!--列表-->
      <el-table :data="overDueList" highlight-current-row @selection-change="selsChange"
                style="width: 100%;">
        <!-- <el-table-column type="selection" width="55" ></el-table-column>
         <el-table-column type="index" width="60"></el-table-column>-->
        <el-table-column prop="overdueId" label="逾期ID" v-if="false"></el-table-column>
        <el-table-column prop="bankCardNo" label="卡号" width="180"></el-table-column>
        <el-table-column prop="customerName" label="姓名" ></el-table-column>
        <el-table-column prop="customerIdCard" label="身份证号" width="220" ></el-table-column>
        <el-table-column prop="bankName" label="贷款银行" width="120" ></el-table-column>
        <el-table-column prop="amount" label="还款额（元）" width="120" ></el-table-column>
        <el-table-column prop="repaymentDate" label="还款日" width="120" ></el-table-column>
        <el-table-column prop="options" label="操作" min-width="180">
          <template scope="scope">
            <el-button type="text" size="small" @click="urge(scope.$index, scope.row)">催收</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination layout="sizes,prev, pager, next" @current-change="getCurrentPage"
                     :page-sizes="[10,20,30,50]" :total="total"
                     :page-size="pagesize"
                     :current-page.sync="currentPage"
                     @size-change="sizeChange"
                     style="text-align: center;margin-top: 20px">
      </el-pagination>
    </div>
    <el-dialog title="请选择对应订单" :visible.sync="dialogTableVisible" :show-close=false>
      <el-table :data="orderList" highlight-current-row @current-change="handleCurrentChange" v-loading="loading">
        <el-table-column property="orderNo" label="订单编号" width="150"></el-table-column>
        <el-table-column property="customerName" label="姓名" width="200"></el-table-column>
        <el-table-column property="customerIdCard" label="身份证号"></el-table-column>
        <el-table-column property="carModel" label="车型"></el-table-column>
        <el-table-column property="loanBankName" label="贷款银行"></el-table-column>
        <el-table-column property="loanAmount" label="贷款金额"></el-table-column>
        <el-table-column property="mobilePhone" label="联系电话"></el-table-column>
        <el-table-column property="gmtCreate" label="申请时间"></el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>
<script>
  import ElForm from "../../../node_modules/element-ui/packages/form/src/form.vue";
  import { Loading } from 'element-ui';
  export default{
    components: {ElForm},
    data(){
      return {
        dialogTableVisible:false,
        condition:null,
        pagesize: 10,
        currentPage:1,
        total: 10,
        filters:{name:''},
        overDueList:[{overdueId:'',bankCardNo:'',customerName:'',customerIdCard:'',bankName:'',amount:'',repaymentDate:''}],
        orderList:[],
        overdueId:'',
        loading:false,
        customerIdCard:'',
      }
    },
    methods: {
      urge(inde, row){
        console.log("loading:"+this.loading)
        this.overdueId = row.overdueId
        this.customerIdCard = row.customerIdCard
        this.$http.get("/overdue/detail/"+row.overdueId)
        .then((response)=>{
          // console.log("totalCount:"+JSON.stringify(response.data.totalCount))
          if(response.data.totalCount=='1'){
            this.$router.push({path:'/AssetProtection/UrgeManageTab',query:{content:response.data.data.data,customerIdCard:this.customerIdCard}})
          }else{
            this.orderList = response.data.data
            this.dialogTableVisible = true
          }
        })
        .catch(function(error){
          console.log(error)
        })
        // this.$router.push({path:'/AssetProtection/UrgeManageTab',query:{overdueId:row.overdueId,customerIdCard:row.customerIdCard}})
      },

      handleCurrentChange(currentRow){
        this.loading =true
        this.$http.get("/overdue/detail/order/"+currentRow.orderNo)
        .then((response)=>{
          this.loading =false
          if(response.data.success){
            //loadingInstance.close();
            this.dialogTableVisible = false
            this.$message('查询成功')
            this.$router.push({path:'/AssetProtection/UrgeManageTab',query:{content:response.data.data,customerIdCard:this.customerIdCard}})
          }else{
            this.$message('查询失败')
          }
        })
        .catch(function(error){
          console.log(error)
        })
      },

      getOverDueList(){
        this.$http.get("/overdue/list",{
          params:{
            pageSize:this.pagesize,
            pageNo:this.currentPage,
            queryCondition:this.condition
          }
        })
        .then((response)=>{
          console.log("overDueList:"+JSON.stringify(response.data.data))
          this.total=response.data.totalCount
          this.overDueList = response.data.data
        })
        .catch(function(error){
          console.log(error)
        })
      },

      uploadSuccess(response , file , fileList){
        this.getOverDueList()
      },

      searchCustomer(){
        this.condition = this.filters.name
        this.getOverDueList()
      },

      sizeChange(val){
        this.pagesize = val
        this.getOverDueList()
      },

      getCurrentPage(currentPage){
        this.currentPage = currentPage
        this.getOverDueList()
      },
    },
    mounted() {
      this.getOverDueList()
    }
  }
</script>

<style lang="scss" scoped>
.content {
  padding: 10px;
  background: #F7F7F7;
  .title {
    color: #99A9BF;
    font-size: 14px;
    line-height: 18px;
    margin: 8px 0px 10px 0px;
  }
  .main-content {
    background: #fff;
    position: fixed;
    top: 96px;
    bottom: 10px;
    left: 216px;
    right: 16px;
    overflow: auto;
    padding: 20px;
  }
}
</style>